package m.app.action.fun;

import m.app.action.AppAction;
import m.base.util.PowerUtil;
import m.common.action.ActionMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.model.util.QueryOrder;
import m.fun.model.GoodsOffer;
import m.fun.model.OfferInfo;
import m.store.model.GuestInfo;
import m.system.document.DocumentMeta;
import m.system.document.DocumentMethodMeta;
import m.system.document.DocumentParamMeta;
import m.system.util.JSONMessage;
import m.system.util.StringUtil;

@ActionMeta(name = "app/fun/offerInfo",title = "app报价单")
public class OfferInfoAction extends AppAction {
    private OfferInfo model;
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "我的报价单列表",permission = true),
        params = {
            @DocumentParamMeta(name = "page.index",description = "分页开始位置",type = FieldType.INT),
            @DocumentParamMeta(name = "page.num",description = "分页每页数量",type = FieldType.INT),
            @DocumentParamMeta(name = "params[oid@eq]",description = "条件示例，字段和操作符中间用@，值为空不添加",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid#desc]",description = "排序示例，字段和操作符中间用#，值为空不生效",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage myList() throws Exception {
        verifyOfferFunc();
        ModelQueryList queryList=toQueryList(OfferInfo.class,"*");
        queryList.addCondition(QueryCondition.eq("user.oid", PowerUtil.getSessionUserOid()));
        return JSONMessage.success("查询成功").push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "查询报价单信息",permission = true),
        params = {
            @DocumentParamMeta(name = "model.oid",description = "报价单oid",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage getInfo() throws Exception {
        if(null!=model&&!StringUtil.isSpace(model.getOid())){
            model= ModelQueryList.getModel(model,"*");
        }else{
            model=new OfferInfo();
            model.setTitle("报价单");
            model.setDescription("");
            model.setUser(PowerUtil.getSessionUser(true));
            model.setStore(PowerUtil.getSessionStore(true));
            model.setContact(model.getUser().getRealname());
            model.setTel(model.getUser().getPhone());
            model.setAddress(PowerUtil.getSessionStore(true).getAddress());
        }
        return JSONMessage.success("查询成功")
                .push("model",model);
    }

    public OfferInfo getModel() {
        return model;
    }

    public void setModel(OfferInfo model) {
        this.model = model;
    }
}
